﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Frogism.Core;

namespace Frogism.Data._2 {
  public class AuthorRepository:Frogism.Core.IAuthorManager   {
   
    //public Author GetAuthor(int id) {
    //  using (NHibernate.ISession session = NHConfig.GetSessionFactory().OpenSession()) {
    //    return session.Get<Author>(id);
    //  }
    //}
    public Frogism.Core.IAuthor Insert(Frogism.Core.Author a) {
      using (NHibernate.ISession session = NHConfig.GetSessionFactory().OpenSession()) {
        using (NHibernate.ITransaction trans = session.BeginTransaction()) {
          session.Save(a);
          trans.Commit();
        }
      }
      return a;
    }

    public Frogism.Core.IAuthor Get(int id) {
      using (NHibernate.ISession session = NHConfig.GetSessionFactory().OpenSession()) {
        return session.Get<Author>(id);
      }
    }

    public IEnumerable<Frogism.Core.IAuthor> GetAll() {
      using (NHibernate.ISession session = NHConfig.GetSessionFactory().OpenSession()) {
        return session.CreateQuery("from Author").List<IAuthor>();
      }
    }
  }
}
